package cn.tedu.charging.cost.dao.repository.impl;

import cn.tedu.charging.cost.dao.mapper.ChargingRuleMapper;
import cn.tedu.charging.cost.dao.repository.ChargingRuleRepository;
import cn.tedu.charging.cost.pojo.po.CostRulePO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

@Repository
public class ChargingRuleRepositoryImpl implements ChargingRuleRepository {

    @Autowired
    private ChargingRuleMapper chargingRuleMapper;


    @Override
    public List<CostRulePO> getCostRules(Integer stationId) {
        QueryWrapper<CostRulePO> costRulePOQueryWrapper = new QueryWrapper<>();
        costRulePOQueryWrapper.eq("station_id", stationId);   // 根据站id进行匹配
        // 方法需要返回一个 List<CostRulePO>，而 selectList 正好返回 List<T> 类型的结果。
        List<CostRulePO> costRulePOS = chargingRuleMapper.selectList(costRulePOQueryWrapper);    // SELECT * FROM charging_cost_rule WHERE station_id = ?
        return costRulePOS == null ? Collections.emptyList() : costRulePOS;
    }
}
